package c.j.a.c;

import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
import c.j.a.a.a.c.b;
import c.j.a.a.a.c.c;
import c.j.a.a.a.c.e;
import c.j.a.b.a.a.a;
import c.j.a.b.a.d;
import c.j.a.c.g.y;
import com.huawei.hms.jos.games.ranking.RankingConst;
import java.util.Objects;
import org.json.JSONException;
import org.json.JSONObject;

/* compiled from: AdWebViewDownloadManagerImpl */
public class j implements d {
    public static volatile j b;
    public z a = z.a(y.a());

    public static b a(boolean z) {
        a.b bVar = new a.b();
        bVar.a = 0;
        bVar.c = true;
        bVar.f = false;
        if (z) {
            bVar.b = 2;
        } else {
            bVar.b = 0;
        }
        return bVar.a();
    }

    public static b d() {
        return a(false);
    }

    public static c e() {
        c.j.a.b.a.a.b.b bVar = new c.j.a.b.a.a.b.b();
        String str = "landing_h5_download_ad_button";
        bVar.a = str;
        bVar.b = str;
        bVar.c = "click_start_detail";
        bVar.d = "click_pause_detail";
        bVar.e = "click_continue_detail";
        bVar.f = "click_install_detail";
        bVar.g = "storage_deny_detail";
        bVar.h = 1;
        bVar.i = false;
        bVar.j = false;
        return bVar.a();
    }

    public boolean b(Context context, long j, String str, e eVar, int i) {
        c.j.a.b.a.c.a aVar = (c.j.a.b.a.c.a) c.j.a.c.g$g.d.c.a.e.get(Long.valueOf(j));
        if (aVar != null) {
            this.a.b(context, i, null, aVar.a());
            return true;
        }
        c.j.a.a.a.c.d dVar = (c.j.a.a.a.c.d) c.j.a.c.g$g.d.c.a.b.get(Long.valueOf(j));
        if (dVar == null) {
            return false;
        }
        this.a.b(context, i, null, dVar);
        return true;
    }

    public boolean c(Context context, Uri uri, c.j.a.a.a.c.d dVar, c cVar, b bVar) {
        Uri uri2 = uri;
        c.j.a.a.a.c.d dVar2 = dVar;
        o.b bVar2 = o.b.b.a;
        if (!y.i(uri) || y.t().optInt("disable_market") == 1) {
            return false;
        }
        Context a = context == null ? y.a() : context;
        String f = c.j.a.c.q.d.f(uri2.getQueryParameter("id"), uri2.getQueryParameter("packagename"), uri2.getQueryParameter("pkg"), uri2.getQueryParameter("package_name"), uri2.getQueryParameter(RankingConst.RANKING_JGW_APPID));
        ((a) bVar).b = 2;
        c.j.a.b.a.a.c cVar2 = (c.j.a.b.a.a.c) dVar2;
        c[] cVarArr = new c[]{cVar, e()};
        c.j.a.b.a.a.c cVar3 = cVar2;
        c.j.a.c.g$g.d.b bVar3 = r1;
        c.j.a.c.g$g.d.b bVar4 = new c.j.a.c.g$g.d.b(cVar2.a, dVar, (c) c.j.a.c.q.d.e(cVarArr), bVar);
        if (!TextUtils.isEmpty(f)) {
            cVar3.f = f;
        }
        if (c.j.a.c.q.d.l(dVar) && c.j.a.d.b.l.a.f.b("app_link_opt", 0) == 1 && y.j(bVar3)) {
            return true;
        }
        bVar4 = bVar3;
        bVar2.h("market_click_open", dVar2, bVar4.c);
        c.j.a.c.g$g.e b = y.b(a, f);
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("market_url", uri.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (b.a == 5) {
            bVar2.o("market_open_success", jSONObject, bVar4);
            c.j.a.a.a.a.b p = y.p();
            bVar4.b.v();
            Objects.requireNonNull((y.a) p);
            c.j.a.b.a.c.a aVar = new c.j.a.b.a.c.a(bVar4.b, bVar4.c, bVar4.d, 0);
            if (!TextUtils.isEmpty(f)) {
                aVar.e = f;
            }
            aVar.d = 2;
            aVar.f(System.currentTimeMillis());
            aVar.N = 4;
            c.j.a.c.g$g.d.c.a.e(aVar);
            return true;
        }
        try {
            jSONObject.put("error_code", b.b);
        } catch (JSONException e2) {
            e2.printStackTrace();
        }
        bVar2.o("market_open_failed", jSONObject, bVar4);
        return false;
    }
}
